<template>
	<view class="page">
		<view class="page__bd">
			<view class="my-item" style='background:none;display:flex;flex-direction:column;height:auto;'></view>
			<view class="my-item" style='background:none;display:flex;padding-left:30rpx;'>
				<view style="margin-right: 20px;">付款账户</view>
				<input class="text" v-model="userHash" />
			</view>
			<view class="my-item" style='background:none;display:flex;padding-left:30rpx;'>
				<view style="margin-right: 20px;">可用余额</view>
				<input class="text" v-model="amount" />
			</view>


			<view class="my-item" style='background:none;display:flex;padding-left:30rpx;'>
				<view style="margin-right: 20px;">收款账户</view>
				<input class="text" placeholder="请输入收款账户" v-model="toUserHash" />
			</view>
			<view class="my-item" style='background:none;display:flex;padding-left:30rpx;'>
				<view style="margin-right: 20px;">转账金额</view>
				<input class="text" placeholder="请输入转账金额" v-model="toAmount" />
			</view>


			<view class="page__bd page__bd_spacing zrbtn">
				<view class="button-sp-area">
					<button class="weui-btn" @tap="transfer" type="warn">立即转入</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userHash: getApp().globalData.userData['MgxHashID'],
				//toUserHash: "0c8256cb55462ec97b90584343e9acf6201550e4540feb0ab3fd2c598b9795a2",//收款账户
				toUserHash: '',
				amount: 0, //可用余额
				toAmount: null //转账金额
			}
		},
		onLoad: function() {
			uni.request({
				url: 'http://' + getApp().globalData.mpAddress + '/getbalance',
				method: 'GET',
				data: {
					hash: getApp().globalData.userData['MgxHashID']
				},
				success: res => {
					console.log(res.data)
					this.amount = res.data.amount
				},
				fail: () => {},
				complete: () => {}
			});
		},
		methods: {

			transfer: function() {
				var that = this;
				if (!this.toUserHash) {
					uni.showToast({
						title: '请输入收款账户',
						icon: "none",
						duration: 2000
					});
					return false;
				}
				if (!this.toAmount) {
					uni.showToast({
						title: '请输入转账额',
						icon: "none",
						duration: 2000
					});
					return false;
				}
				uni.request({
						url: 'http://' + getApp().globalData.mpAddress + '/xfer',
						method: 'GET',
						data: {
							'from': this.userHash,
							'to': this.toUserHash,
							'amount': this.toAmount
						},
						success: res => {
							console.log(res.data)
							console.log(res.data.Code)
							if (res.data.ret != 0) {
								uni.showToast({
									title: '转账失败：' + res.data.Msg,
									icon: "none",
									duration: 3000
								});
							} else if (res.data.ret == 0) {
								uni.showToast({
									title: '转账成功',
									icon: "success",
									duration: 3000
								});
							}
						},
						fail: () => {},
						complete: () => {}
					});

			}

		}
	}
</script>

<style>
	.srlab {
		float: left;
	}

	.srtext {
		float: right;

	}


	.my-item {
		width: 100%;
		background: url(https://cdn.it120.cc/images/weappshop/arrow-right.png) no-repeat 750rpx center;
		background-size: 16rpx auto, 750rpx auto;
		margin: 0;
		border-bottom: 1px solid #eee;
		height: 100rpx;
		line-height: 100rpx;
	}

	.my-item navigator {
		padding-left: 50rpx;
	}

	.qiandao {
		height: 80rpx;
		line-height: 80rpx;
		margin-right: 70rpx;
		margin-top: 10rpx;
	}

	.zrbtn {
		margin-top: 50px;
	}
</style>
